local juanshe = fk.CreateSkill{
    name = "wk_heg__juanshe",
}

Fk:loadTranslationTable{
    ["wk_heg__juanshe"] = "蠲奢",
    [":wk_heg__juanshe"] = "与你势力相同角色的结束阶段，你可令其弃置一张手牌并回复1点体力，然后直至其回合开始或你受到伤害，其不能使用手牌。",

    ["@@wk_heg__juanshe-prohibit"] = "蠲奢 禁用手牌",
    ["#wk_heg__juanshe-invoke"] = "蠲奢：是否令当前回合角色弃置一张手牌，然后其回复1点体力",

    ["$wk_heg__juanshe1"] = "自古，就是邪不胜正！。",
    ["$wk_heg__juanshe2"] = "主公面前，岂容小人搬弄是非。",
}

local H = require "packages/ol_hegemony/util"

juanshe:addEffect(fk.EventPhaseStart,{
    anim_type = "support",
    can_trigger = function (self, event, target, player, data)
    --    local events = target.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
    --    local use = e.data
    --     return use.from == target end, Player.HistoryTurn)
        -- return #events < target:getMaxCards() and 
        return H.compareKingdomWith(player, target) and target.phase == Player.Finish and player:hasSkill(juanshe.name)
        and not target:isKongcheng() and target:isWounded()
    end,
    on_cost = function (self, event, target, player, data)
       return player.room:askToSkillInvoke(player, {skill_name = juanshe.name, prompt = "#wk_heg__juanshe-invoke"})
    end,
    on_use = function (self, event, target, player, data)
       local room = player.room
       room:askToDiscard(target,{
        min_num = 1,
        max_num = 1,
        include_equip = false,
        skill_name = juanshe.name,
        cancelable = false,
       })
       if target:isWounded() then
        room:recover({
           who = target,
           num = 1,
           recoverBy = player,
           skillName = juanshe.name,
          })
       end
       room:setPlayerMark(target, "@@wk_heg__juanshe-prohibit", 1)
    end,
})

juanshe:addEffect(fk.TurnStart,{
    can_refresh = function(self, event, target, player, data)
        return target:getMark("@@wk_heg__juanshe-prohibit") > 0
    end,
    on_refresh = function(self, event, target, player, data)
        player.room:setPlayerMark(target, "@@wk_heg__juanshe-prohibit", 0)
    end,
})

local juanshe_spec = {
    can_refresh = function(self, event, target, player, data)
        return target == player and player:hasSkill(juanshe.name)
    end,
    on_refresh = function(self, event, target, player, data)
        for _, p in ipairs(player.room.alive_players) do
          if p:getMark("@@wk_heg__juanshe-prohibit") > 0 then
            player.room:setPlayerMark(p, "@@wk_heg__juanshe-prohibit", 0)
        end
      end
    end,
}

juanshe:addEffect(fk.BuryVictim, juanshe_spec)
juanshe:addEffect(fk.Damaged, juanshe_spec)

juanshe:addEffect("prohibit",{
    prohibit_use = function(self, player, card)
       if player:getMark("@@wk_heg__juanshe-prohibit") == 0 then return false end
       local subcards = Card:getIdList(card)
       return #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player:getCardIds(Player.Hand), id)
       end)
    end,
})

return juanshe